package org.nowcoder.leetcode.hashTable;

import java.util.Arrays;

/**
 * Title  : 242. Valid Anagram
 * Source : https://leetcode.cn/problems/valid-anagram/?envType=study-plan-v2&envId=top-interview-150
 * Author : XrazYang
 * Date   : 2023-08-01
 */
public class LeetCode_242 {
    public boolean isAnagram(String s, String t) {
        //边界条件
        if (s.length() == t.length()) {
            int[] salpha = new int[26];
            int[] talpha = new int[26];

            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                salpha[c - 'a'] += 1;
            }

            for (int i = 0; i < t.length(); i++) {
                char c = t.charAt(i);
                talpha[c - 'a'] += 1;
            }
            return Arrays.equals(salpha, talpha);
        }
        return false;
    }
}
